package cn.pms.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.support.WebApplicationContextUtils;

import cn.pms.po.Date;
import cn.pms.po.Month;
import cn.pms.po.WorkTime;
import cn.pms.po.Year;
import cn.pms.test.emp.EmployeeTest;

public class ContextListener implements ServletContextListener
{
	@Override
	public void contextDestroyed(ServletContextEvent context)
	{}
	
	@Override
	public void contextInitialized(ServletContextEvent context)
	{
		WebApplicationContextUtils
				.getWebApplicationContext(context.getServletContext())
				.getBean(EmployeeTest.class).testAdd();
		WorkTime workTime = new WorkTime(700, 1700);
		Month month = new Month(new Year(2013), cn.pms.type.Month.JANUARY, null);
		Date currentDate = new Date();
		currentDate.setDate(new java.util.Date());
		currentDate.setIsWork(true);
		currentDate.setWorkTime(workTime);
		currentDate.setMonth(month);
		context.getServletContext().setAttribute("currentDate", currentDate);
	}
}
